﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;

namespace Turtle
{
    /// <summary>
    /// Lógica de interacció tortuga.
    /// </summary>
    public partial class Window1 : Window
    {
        public int AngleDireccio;

        public Window1()
        {
            InitializeComponent();
            AngleDireccio = 0;
        }

        private void txtCommand_KeyDown(object sender, KeyEventArgs e)
        {
            string com = "";

            if (e.Key == Key.Enter)
            {
                com = this.txtCommand.Text;
                this.txtCommand.Clear();

                String regAd = "^ad\\s[0-9]+";
                String regAdOnlyNumber = "[0-9]+";
                if (System.Text.RegularExpressions.Regex.IsMatch(com, regAd))
                {
                    Match m = Regex.Match(com, regAdOnlyNumber);
                    Console.WriteLine(m.Groups[0].Value);

                    //Obtenir el sinus i el cosinus de l'angle 
                    //per determinar la nova direcció.

                    this.myTurtle.Margin = new Thickness(this.myTurtle.Margin.Left,
                        this.myTurtle.Margin.Top - int.Parse(m.Groups[0].Value), 
                        this.myTurtle.Margin.Right, this.myTurtle.Margin.Bottom);
                }
            }    
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.myTurtle.Margin = new Thickness(this.myCanvas.ActualWidth / 2, 
                this.myCanvas.ActualHeight / 2, 
                0, 0);
            //Caldria restar el tamany de la tortuga.
        }
    }
}
